home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-11
/
tagbr.zip
/
TAGBROW.PRG
< prev
next >
Wrap
Text File
|
1993-04-22
|
5KB
|
147 lines
/*
┌──────────────────────────────────────────────────────────────────────────┐
│ Application: Example of a tagging browse object │
│ File Name: TAGBROW.PRG │
│ Author: Nicholas Solomon │
└──────────────────────────────────────────────────────────────────────────┘
*/
#include "inkey.ch"
#include "tagbrow.ch"
/*
┌──────────────────────────────────────────────────────────────────────────┐
│ Function: TAGBROW() │
├──────────────────────────────────────────────────────────────────────────┤
│ Description: allow user a taggable browse pick object │
│ Params: cFieldName = Name of field used for selection │
│ cColName = Column header for above col. object │
│ nTop = top row of object │
│ nLeft = left col of object │
│ lMessage = .t. = include message (default to .t.) │
│ cTitle = title a box around the object │
│ Return: (aSelected) = record numbers of selected items │
└──────────────────────────────────────────────────────────────────────────┘
*/
function tagbrow( cFieldName, cColName, nTop, nLeft, lMessage, cTitle)
local tb_methods := { ;
{K_DOWN, {|b| b:down()}}, ;
{K_UP, {|b| b:up()}}, ;
{K_CTRL_PGUP, {|b| b:gotop() }},;
{K_CTRL_PGDN, {|b| b:gobottom() }},;
{K_PGDN, {|b| b:pagedown()}}, ;
{K_PGUP, {|b| b:pageup()}}, ;
{K_HOME, {|b| b:gotop()}}, ;
{K_END, {|b| b:gobottom()}} }
local meth_no, column, aSelected:={}
local b,exit_request:=.f.,lkey,skey:="", nFound, cOldColor:=setcolor()
local nLenField, bSelect, cScreen:=savescreen(0,0,maxrow(),maxcol())
local bField := fieldblock( cFieldName )
DEFAULT cColName TO cFieldName
DEFAULT lMessage TO .t.
/* get length of browse field to determine width of browse screen */
nLenField := len(eval(bField))
/* build a box if cTitle was passed - could be done better! */
if cTitle != NIL
@ nTop-1, nLeft-1 to maxrow()-3, nLeft + nLenField+1 color 'W/B'
@ nTop-1, ( nLeft + ( int( (nLeft + nLenField) - (nLeft-1) ) / 2 ) ) - ;
( int( len(cTitle) / 2 ) ) - 1 say '┤' + cTitle + '├' ;
color 'RB+/B'
endif
/* declare browse object */
b := TBrowseDB( nTop, nLeft , maxrow()-4, nLeft+nLenField )
b:headsep := "═══"
b:footsep := "═══"
b:colorspec := "W/B,N/W,R+/B,R+/W,W+/B,W/N,N/W"
/*
the first column MUST be the array for
selected (tagged) record numbers
*/
column := TBColumnNew( ' ',;
{|| iif( ascan( aSelected, recno() ) !=0,;
CHECKMARK,' ') } )
column:width:=1
column:defColor := { 3, 3 }
column:colorBlock := {|| { 5, 5 } }
b:addColumn( column )
/*
block to highlight selected vs. unselected items
*/
bSelect := {|| iif( ascan( aSelected, recno() ) != 0,;
{ 3, 4 } , { 1, 2 } ) }
column := TBColumnNew( cColName, bField )
column:defColor := { 3,3}
column:colorBlock := bSelect
b:addColumn( column )
/*
freeze the first column - don't allow them to go into it
*/
b:freeze := 1
dispbegin()
do while !b:stabilize() ; enddo
dispend()
do while !exit_request
/* keep 'em out of first column */
if b:colPos <= b:freeze
b:colPos := b:freeze + 1
endif
do while nextkey() = 0 .and. !b:stabilize() ; enddo
lkey = inkey( 0)
meth_no = ascan( tb_methods,{|elem| lkey = elem[1]})
if meth_no != 0
eval( tb_methods[meth_no,2],b)
else
do case
/* deletes ALL selections */
case lkey == K_DEL
aSelected:={}
if lMessage
@ maxrow(),0 say padc('You have selected '+alltrim(str(len(aSelected))) + ;
' ' + iif(len(aSelected)=1,'item','items'), maxcol())
endif
b:refreshall()
/* select-unselect element */
case lkey == K_ENTER
if ( (nFound:=ascan(aSelected, recno() )) != 0 )
adel(aSelected, nFound)
asize(aSelected, (len(aSelected)-1))
else
aadd(aSelected, recno() )
endif
/* simply inform user how many are selected */
if lMessage
@ maxrow(),0 say padc('You have selected '+alltrim(str(len(aSelected))) + ;
' ' + iif(len(aSelected)=1,'item','items'), maxcol())
endif
b:refreshcurrent()
case lkey = K_ESC
exit_request = .T.
/*
this simply allows user to jump
as alpha keys are typed --
not much good in this example !
*/
case ( lkey > 47 .and. lkey < 123) .or. ;
lkey = 32 .or. lkey = 39
if ! dbseek( upper( chr( lkey)))
dbgotop()
endif
b:refreshall()
endcase
endif
enddo
setcolor( cOldColor )
restscreen(0,0,maxrow(),maxcol(), cScreen)
return(aSelected)